import 'package:flutter/material.dart';

import '../../Pojo/News_Itme_Pojo.dart';
import '../NewValue/NewValue.dart';

class ItmeIndex extends StatefulWidget {
  final String keys;
  const ItmeIndex({Key? key,required this.keys}) : super(key: key);


  @override
  State<ItmeIndex> createState() => _ItmeIndexState(Keys: keys);
}

class _ItmeIndexState extends State<ItmeIndex> {
  //唯一标识
  final String Keys;

  _ItmeIndexState({required this.Keys});

  final BackImageUrls="https://img0.baidu.com/it/u=792554660,3933923766&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500";

  final String UserImageUrls="https://img2.baidu.com/it/u=2091771371,1112634019&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500";

  String Number="5.8W";
  String strl="";
  bool flag=true;

  bool bludFlag=false;





  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print(Keys);
      strl="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        elevation: 0,
        titleTextStyle: TextStyle(
          color: Colors.black,
          fontSize: 26,
        ),
        leading: Container(
          child:GestureDetector(
            onTap: (){
              Navigator.pop(context);
            },
            child: Icon(Icons.arrow_circle_left,color: Colors.blue,size: 40),
          ),
        ),
      ),
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Container(
          margin: EdgeInsets.all(4),
          width: double.infinity,
          child: Column(
            children: [
              Container(
                width: double.infinity,
                height: 300,
                child: Column(
                  children: [
                    Expanded(
                        flex: 4,
                        child: Container(
                          width: double.infinity,
                          child: Image.network(BackImageUrls,fit: BoxFit.fitWidth,),
                        ),
                    ),
                    Expanded(
                      flex: 5,
                      child: Container(
                        padding: EdgeInsets.all(10),
                        width: double.infinity,
                        child: Column(
                          children: [
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                //头像
                                Container(
                                  width: 90,
                                  height: 90,
                                  decoration: BoxDecoration(
                                    image: DecorationImage(
                                        image: NetworkImage(
                                          UserImageUrls
                                        ),
                                      ),
                                    borderRadius: BorderRadius.all(Radius.circular(50))
                                      )
                                  ),
                                //相关信息
                                Container(
                                  child: Container(
                                    width: 240,
                                    height: 90,
                                    child:Column(
                                      children: [
                                        Row(
                                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                                          crossAxisAlignment: CrossAxisAlignment.center,
                                          children: [
                                            Container(
                                              alignment: Alignment.centerLeft,
                                              height: 40,
                                              width: 100,
                                              child: Text("粉丝 : $Number",style: TextStyle(
                                                fontSize: 16
                                              ),),
                                            ),
                                            Container(
                                              alignment: Alignment.centerLeft,
                                              height: 40,
                                              width: 100,
                                              child: Text("关注 : $Number",style: TextStyle(
                                                fontSize: 16
                                              ),),
                                            ),
                                          ],
                                        ),
                                        //关注按钮
                                        Row(
                                          mainAxisAlignment: MainAxisAlignment.center,
                                          crossAxisAlignment: CrossAxisAlignment.center,
                                          children: [
                                            bludFlag ?
                                            //    关注之后
                                            ElevatedButton(
                                              onPressed: (){
                                                setState(() {
                                                  this.bludFlag=!this.bludFlag;
                                                });
                                              },
                                              child: Text("已经关注"),
                                              style: ButtonStyle(
                                                fixedSize: MaterialStateProperty.all(Size(238, 38)),
                                                backgroundColor:MaterialStateProperty.all(Colors.black12)
                                              ),
                                            ):
                                            //    没有关注
                                            ElevatedButton(
                                              onPressed: (){
                                                setState(() {
                                                  this.bludFlag=!this.bludFlag;
                                                });
                                              },
                                              child: Text("关注"),
                                              style: ButtonStyle(
                                                  fixedSize: MaterialStateProperty.all(Size(238, 38))
                                              ),
                                            ),
                                          ],
                                        ),
                                      ],
                                    ),
                                  )
                                ),
                              ],
                            ),
                            const Divider(
                              height: 20,
                              color: Colors.black38,
                            ),
                            Container(
                              width: double.infinity,
                              child: Text(
                                "简介:$strl",
                                style: const TextStyle(
                                  fontSize: 14,
                                ),
                                overflow: TextOverflow.clip,
                                textDirection: TextDirection.ltr,
                                maxLines: 2,
                              ),
                            ),
                          ],
                        ),
                        // color: Colors.cyan,
                      ),
                    ),
                  ],
                ),
              ),
              Divider(
                height: 20,color: Colors.black38,
              ),
              Container(
                width: double.infinity,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Container(
                      alignment: Alignment.centerRight,
                      padding: const EdgeInsets.fromLTRB(0, 0, 16, 0),
                      height: 26,
                      width: double.infinity,
                      child: GestureDetector(
                        child: Text(flag?"时间排序":"热度排序",style: TextStyle(
                          fontSize: 16,
                          color: Colors.blue.shade600
                        ),),
                        onTap: (){
                          setState(() {
                            this.flag=!flag;
                          });
                        },
                      ),
                    ),
                    Column(
                      children: [
                        AttentionHomeItme(
                            NIP: NewsItmePojo(
                              "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
                              "2023/1/2",
                              "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
                              "某某日报",
                              "2",
                            ),
                        ),
                        AttentionHomeItme(
                          NIP: NewsItmePojo(
                            "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
                            "2023/1/2",
                            "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
                            "某某日报",
                            "2",
                          ),
                        ),
                        AttentionHomeItme(
                          NIP: NewsItmePojo(
                            "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
                            "2023/1/2",
                            "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
                            "某某日报",
                            "2",
                          ),
                        ),
                        AttentionHomeItme(
                          NIP: NewsItmePojo(
                            "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
                            "2023/1/2",
                            "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
                            "某某日报",
                            "2",
                          ),
                        ),
                        AttentionHomeItme(
                          NIP: NewsItmePojo(
                            "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
                            "2023/1/2",
                            "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
                            "某某日报",
                            "2",
                          ),
                        ),
                        AttentionHomeItme(
                          NIP: NewsItmePojo(
                            "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
                            "2023/1/2",
                            "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
                            "某某日报",
                            "2",
                          ),
                        ),
                        AttentionHomeItme(
                          NIP: NewsItmePojo(
                            "http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg",
                            "2023/1/2",
                            "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
                            "某某日报",
                            "2",
                          ),
                        ),
                      ],
                    )
                  ],
                ),
                // width: double.infinity,
              ),
            ],
          ),
        ),
      ),
    );
  }
}



class AttentionHomeItme extends StatelessWidget {

  final NIP;

  const AttentionHomeItme({Key? key ,required this.NIP}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(4.0, 10, 4.0, 0),
      decoration: BoxDecoration(
        border: Border.all(
          color: Colors.black26,
          width: 1.0,
        ),
        borderRadius: BorderRadius.all(Radius.circular(4)),
      ),
      height: 102,
      width: double.infinity,
      child: GestureDetector(
        onTap: (){
          Navigator.push(context, MaterialPageRoute(builder: (context)=>NewValue(NewKey: NIP.newsKey,)));
        },
        child: Column(
          children: [
            Container(
              child: Row(
                children: [
                  // 图片
                  Expanded(
                    flex: 3,
                    child: Container(
                      padding: const EdgeInsets.all(4),
                      height: 100,
                      child: Image.network(
                        NIP.imageUrl,
                        fit: BoxFit.fill,
                      ),
                    ),
                  ),
                  //文字
                  Expanded(
                    flex: 7,
                    child: Container(
                      height: 100,
                      width: double.infinity,
                      child: Column(
                        children: [
                          //标题
                          Expanded(
                            flex: 7,
                            child: Container(
                              padding: const EdgeInsets.all(4),
                              width: double.infinity,
                              //标题
                              child: Text(
                                NIP.titleValue,
                                style: TextStyle(
                                    fontWeight: FontWeight.w600,
                                    fontSize: 14
                                ),
                              ),
                            ),
                          ),
                          //注释
                          Expanded(
                              flex: 3,
                              child: Container(
                                padding: const EdgeInsets.all(4),
                                width: double.infinity,
                                child: Container(
                                  width: double.infinity,
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.end,
                                    children: [
                                      //  日期
                                      Container(
                                        alignment: Alignment.center,
                                        height: double.infinity,
                                        margin: const EdgeInsets.fromLTRB(0, 0, 10, 0),
                                        //绑定时间
                                        child: Text(NIP.timeValue,
                                          style: TextStyle(
                                              fontSize: 14
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                )
                                // height: ,
                              )
                          ),
                        ],
                      ),
                    ),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}


